package com.yanqu.road.server.manger.activity.dafuweng.event;

import com.yanqu.road.entity.activity.dafuweng.DFWConfig;
import com.yanqu.road.entity.activity.dafuweng.DFWEvent;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.server.manger.activity.dafuweng.building.BaseDFWBuilding;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

/**
 * @Author wpj
 * @Date 2021/1/7
 */
public class DFWNormalEvent extends BaseDFWEvent {

    public DFWNormalEvent(BaseDFWBuilding baseDFWBuilding, DFWEvent dfwEvent) {
        super(baseDFWBuilding, dfwEvent);
    }

    @Override
    public void doEvent() {
        DFWConfig config = baseDFWBuilding.getDfwConfig();
        // 获取技能加成
        List<Integer> mapSkillAddition = DaFuWengMgr.getMapSkillAddition(config, userData.getGoldScore());
        List<Integer> dollSkillAddition = DaFuWengMgr.getDollSkillAddition(config, userData.getDollList());
        List<Integer> godSkillAddition = DaFuWengMgr.getGodSkillAddition(config, userData.getDfwGodDataList());
        List<Integer> unionSkillAddition = DaFuWengMgr.getUnionSkillAddition(config, baseDFWBuilding.getUnionUid());
        int goldAddition = 1000 + mapSkillAddition.get(0) + dollSkillAddition.get(0) + godSkillAddition.get(0) + unionSkillAddition.get(0);
        Property property = PropertyHelper.parseStringToProperty(dfwEvent.getRewards());
        int golden = property.getCountByGoodsId(eItemId.DFW_GOLDEN.getValue()).intValue();
        if (golden > 0) {
            golden = new BigDecimal(goldAddition).multiply(new BigDecimal(golden)).divide(new BigDecimal(1000), 0, BigDecimal.ROUND_UP).intValue();
            userData.setGoldScore(userData.getGoldScore() + golden);
            baseDFWBuilding.getPlayer().notifyListener(eGamePlayerEventType.DaFuWengScoreRank.getValue(), userData.getGoldScore());
            baseDFWBuilding.getPlayer().notifyListener(eGamePlayerEventType.DaFuWengUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_NORMAL, BigInteger.valueOf(userData.getGoldScore()), baseDFWBuilding.getUnionUid()));
            baseDFWBuilding.getPlayer().getModule(CurrencyModule.class).addCurrency(
                    new Property(eItemId.DFW_GOLDEN.getValue(), BigInteger.valueOf(golden)), eLogMoneyType.DaFuWeng, eLogMoneyType.DaFuWengNormalEvent
            );
            reward = eItemId.DFW_GOLDEN.getValue() + "=" + golden;
        }
    }
}
